<?php
/*
|------------------------------------------------------------------|
|	Level5 - Wordpress Theme Framework
|
|	Copyright (c) Brixter de Leon
|	http://frostproject.org
|	deleon.brixter@gmail.com
|
|	This program is free software; you can redistribute it and/or
|	modify it under the terms of the GNU General Public License
|	as published by the Free Software Foundation; either version 2
|	of the License, or (at your option) any later version.
|
|	This program is distributed in the hope that it will be useful,
|	but WITHOUT ANY WARRANTY; without even the implied warranty of
|	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
|	GNU General Public License for more details.
|
|	You should have received a copy of the GNU General Public License
|	along with this program; if not, write to the Free Software
|	Foundation, Inc., 51 Franklin Street, Fifth Floor, 
|	Boston, MA  02110-1301, USA.
|------------------------------------------------------------------|
*/

if ( ! defined( 'direct_access' ) ) { die( 'Level5' ); }

if ( is_front_page() )
{
	$file = 'index.php';
}
elseif ( is_attachment() )
{
	$file = 'attachment.php'; // Make this above single credits @OTTO wordpress.org
}
elseif ( is_single() )
{
	$file = 'single.php';
}
elseif ( is_page() )
{
	$file = 'page.php';
}
elseif ( is_category() )
{
	$file = 'category.php';
}
elseif ( is_tag() )
{
	$file = 'tag.php';
}
elseif ( is_author() )
{
	$file = 'author.php';
}
elseif ( is_archive() )
{
	$file = 'archive.php';
}
elseif ( is_search() )
{
	$file = 'search.php';
}
elseif ( is_404() )
{
	$file = '404.php';
}
// If index exist...
if ( file_exists( level5_child . level5_template . '/index.php' ) )
{
	// If current page is frontpage, single, page, category, tag, author, archive, search and attachment, make each listed use the theme's index.php.
	if ( is_front_page() || is_single() || is_page() || is_category() || is_tag() || is_author() || is_archive() || is_search() || is_attachment() )
	{
		if ( file_exists( level5_child . level5_template . '/' . $file ) )
		{
			include( level5_child . level5_template . '/' . $file );
		}
		else
		{
			include( level5_child . level5_template . '/index.php' );
		}
	}
	// If current page is neither of those listed above, script will print their usual file and if none is found print default error message.
	else
	{
		if ( file_exists( level5_child . level5_template . '/' . $file ) )
		{
			include( level5_child . level5_template . '/' . $file );
		}
		else
		{
			if( ! file_exists( level5_child . level5_themedefault . '/level5.php' ) )
			{
				die( 'You are missing the default template. Please re-install ' . level5_framename . '.' );
			}
			else
			{
				include( level5_child . level5_themedefault . '/level5.php' );
			}
		}
	}
}
// If index doesn't exist...
else
{
	if( ! file_exists( level5_child . level5_themedefault . '/level5.php' ) )
	{
		die( 'You are missing the default template. Please re-install ' . level5_framename . '.' );
	}
	else
	{
		include( level5_child . level5_themedefault . '/level5.php' );
	}
}
?>